home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / nfsmount / nfsAttr.old < prev    next >
Encoding:
Text File  |  1991-03-24  |  11.3 KB  |  382 lines

  1. /*
  2.  * nfsAttr.c --
  3.  * 
  4.  *    Attribute handling for NFS access.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15. #ifndef lint
  16. static char rcsid[] = "$Header: /sprite/src/cmds/nfsmount/RCS/nfsAttr.c,v 1.7 90/01/25 17:20:19 brent Exp Locker: mottsmth $ SPRITE (Berkeley)";
  17. #endif not lint
  18.  
  19. #include "stdio.h"
  20.  
  21. #include "nfs.h"
  22. #include "sys/stat.h"
  23. #include "kernel/fslcl.h"
  24.  
  25. typedef struct SavedCookie {
  26.     int offset;
  27.     nfscookie cookie;
  28.     struct SavedCookie *next;
  29. } SavedCookie;
  30.  
  31. void NfsToSpriteAttr();
  32. void SpriteToNFsAttr();
  33.  
  34. /*
  35.  *----------------------------------------------------------------------
  36.  *
  37.  * NfsToSpriteDirectory --
  38.  *
  39.  *    Convert from an XDR list of directory entries to a Sprite directory.
  40.  *
  41.  * Results:
  42.  *    This fills in the buffer with a Sprite format directory.
  43.  *
  44.  * Side effects:
  45.  *    This saves the last nfscookie for use with the next READIR rpc.
  46.  *
  47.  *----------------------------------------------------------------------
  48.  */
  49. void
  50. NfsToSpriteDirectory(dirListPtr, offset, countPtr, buffer, fileIDPtr)
  51.     dirlist *dirListPtr;
  52.     int offset;
  53.     int *countPtr;
  54.     char *buffer;
  55.     Fs_FileID *fileIDPtr;
  56. {
  57.     register int count = 0;
  58.     register entry *entryPtr;
  59.     register Fslcl_DirEntry *spriteEntryPtr;
  60.     register int nameLength;
  61.  
  62.     if (dirListPtr->eof) {
  63.     *countPtr = 0;
  64.     fileIDPtr->major = 0;
  65.     return;
  66.     }
  67.     entryPtr = dirListPtr->entries;
  68.     spriteEntryPtr = (Fslcl_DirEntry *)buffer;
  69.     while (entryPtr != (entry *)NULL) {
  70.     nameLength = strlen(entryPtr->name);
  71.     spriteEntryPtr->fileNumber = entryPtr->fileid;
  72.     spriteEntryPtr->nameLength = nameLength;
  73.     strcpy(spriteEntryPtr->fileName, entryPtr->name);
  74.     if (entryPtr->nextentry != (entry *)NULL) {
  75.         spriteEntryPtr->recordLength = Fslcl_DirRecLength(nameLength);
  76.         count += spriteEntryPtr->recordLength;
  77.         spriteEntryPtr = (Fslcl_DirEntry *)((int)spriteEntryPtr +
  78.                         spriteEntryPtr->recordLength);
  79.     } else {
  80.         /* 
  81.          * Make the last entry go up to the end of the directory block.
  82.          * We save the last cookie to support sequential reading of the
  83.          * directory.  To be completely genernal we'd have to save the
  84.          * complete list of cookie/offset pairs.
  85.          */
  86.         register int extraRoom;
  87.         SavedCookie *savedCookie;
  88.  
  89.         extraRoom = FSLCL_DIR_BLOCK_SIZE - (count % FSLCL_DIR_BLOCK_SIZE);
  90.         spriteEntryPtr->recordLength = extraRoom;
  91.         count += extraRoom;
  92.         /*
  93.          * Push a saved cookie onto a list hanging from the major field.
  94.          */
  95.         savedCookie = (SavedCookie *)malloc(sizeof(SavedCookie));
  96.         savedCookie->offset = offset + count;
  97.         bcopy((char *)&entryPtr->cookie, (char *)&savedCookie->cookie,
  98.             sizeof(nfscookie));
  99.         savedCookie->next = (SavedCookie *)fileIDPtr->major;
  100.         fileIDPtr->major = (int)savedCookie;
  101.     }
  102.     entryPtr = entryPtr->nextentry;
  103.     }
  104.     *countPtr = count;
  105. }
  106.  
  107. /*
  108.  *----------------------------------------------------------------------
  109.  *
  110.  * NfsFindCookie --
  111.  *
  112.  *    Look through the list of savedCookie that are hung off the
  113.  *    fileID.major field of a directory to find one that corresponds
  114.  *    to the given offset.
  115.  *
  116.  * Results:
  117.  *    None.
  118.  *
  119.  * Side effects:
  120.  *    None.
  121.  *
  122.  *----------------------------------------------------------------------
  123.  */
  124. void
  125. NfsFindCookie(fileIDPtr, offset, cookiePtr)
  126.     Fs_FileID *fileIDPtr;
  127.     int offset;
  128.     nfscookie *cookiePtr;
  129. {
  130.     register SavedCookie *savedCookiePtr;
  131.     int badCookie = -1;
  132.  
  133.     savedCookiePtr = (SavedCookie *)fileIDPtr->major;
  134.     while (savedCookiePtr != (SavedCookie *)NULL) {
  135.     if (savedCookiePtr->offset == offset) {
  136.         bcopy((char *)&savedCookiePtr->cookie, (char *)cookiePtr,
  137.         sizeof(nfscookie));
  138.         return;
  139.     }
  140.     savedCookiePtr = savedCookiePtr->next;
  141.     }
  142.     printf("NfsFindCookie: no directory cookie for offset %d\n");
  143.     bcopy((char *)&badCookie, (char *)cookiePtr, sizeof(nfscookie));
  144. }
  145.  
  146. /*
  147.  *----------------------------------------------------------------------
  148.  *
  149.  * NfsGetAttrStream --
  150.  *
  151.  *    The default GetAttributes handling procedure called when an
  152.  *    PDEV_GET_ATTR request is received over a request stream.
  153.  *
  154.  * Results:
  155.  *    None.
  156.  *
  157.  * Side effects
  158.  *    None.
  159.  *
  160.  *----------------------------------------------------------------------
  161.  */
  162. /*ARGSUSED*/
  163. ReturnStatus
  164. NfsGetAttrStream(streamPtr, spriteAttrPtr, selectBitsPtr)
  165.     Pdev_Stream *streamPtr;
  166.     Fs_Attributes *spriteAttrPtr;
  167.     int *selectBitsPtr;
  168. {
  169.     register Fs_FileID *fileIDPtr = (Fs_FileID *)streamPtr->clientData;
  170.     register nfs_fh *handlePtr;
  171.     register int status;
  172.     NfsState *nfsPtr;
  173.     attrstat attrStat;
  174.  
  175.     if (fileIDPtr->minor >= 0 && fileIDPtr->minor < nfsFileTableSize) {
  176.     handlePtr = nfsFileTable[fileIDPtr->minor]->handlePtr;
  177.     nfsPtr = (NfsState *)fileIDPtr->serverID;
  178.     nfsPtr->nfsClnt->cl_auth = nfsFileTable[fileIDPtr->minor]->authPtr;
  179.  
  180.     if (clnt_call(nfsPtr->nfsClnt, NFSPROC_GETATTR, xdr_nfs_fh, handlePtr,
  181.             xdr_attrstat, &attrStat, nfsTimeout) != RPC_SUCCESS) {
  182.         clnt_perror(nfsPtr->nfsClnt, "NFSPROC_GETATTR");
  183.         status = FAILURE;
  184.     } else {
  185.         status = attrStat.status;
  186.         if (status == NFS_OK) {
  187.         NfsToSpriteAttr(&attrStat.attrstat_u.attributes, spriteAttrPtr);
  188.         } else {
  189.         status = NfsStatusMap(status);
  190.         }
  191.     }
  192.     } else {
  193.     printf("NfsGetAttrStream: bad fileID <%d,%d,%d,%d>\n", fileIDPtr->type,
  194.         fileIDPtr->serverID, fileIDPtr->major, fileIDPtr->minor);
  195.     status = FAILURE;
  196.     }
  197.     *selectBitsPtr = FS_READABLE | FS_WRITABLE;
  198.     return(status);
  199. }
  200. /*
  201.  *----------------------------------------------------------------------
  202.  *
  203.  * NfsToSpriteAttr --
  204.  *
  205.  *    Map from NFS to Sprite attributes.
  206.  *
  207.  * Results:
  208.  *    Fills in the Sprite attributes from the NFS ones.
  209.  *
  210.  * Side effects
  211.  *    None.
  212.  *
  213.  *----------------------------------------------------------------------
  214.  */
  215. void
  216. NfsToSpriteAttr(nfsAttrPtr, spriteAttrPtr)
  217.     register fattr *nfsAttrPtr;
  218.     register Fs_Attributes *spriteAttrPtr;
  219. {
  220.     spriteAttrPtr->serverID        = -1;
  221.     spriteAttrPtr->domain        = nfsAttrPtr->fsid;
  222.     spriteAttrPtr->fileNumber        = nfsAttrPtr->fileid;
  223.     spriteAttrPtr->type            = nfsToSpriteFileType[(int) nfsAttrPtr->type];
  224.     spriteAttrPtr->size            = nfsAttrPtr->size;
  225.     spriteAttrPtr->numLinks        = nfsAttrPtr->nlink;
  226.     spriteAttrPtr->permissions        = nfsAttrPtr->mode & 07777;
  227.     spriteAttrPtr->uid            = nfsAttrPtr->uid;
  228.     spriteAttrPtr->gid            = nfsAttrPtr->gid;
  229.     spriteAttrPtr->devServerID        = -1;
  230.     if (nfsAttrPtr->type == NFBLK || nfsAttrPtr->type == NFCHR) {
  231.     spriteAttrPtr->devType        = unix_major(nfsAttrPtr->rdev);
  232.     spriteAttrPtr->devUnit        = unix_minor(nfsAttrPtr->rdev);
  233.     } else {
  234.     spriteAttrPtr->devType        = -1;
  235.     spriteAttrPtr->devUnit        = -1;
  236.     }
  237.     spriteAttrPtr->createTime.seconds        = nfsAttrPtr->mtime.seconds;
  238.     spriteAttrPtr->createTime.microseconds    = nfsAttrPtr->mtime.useconds;
  239.     spriteAttrPtr->accessTime.seconds        = nfsAttrPtr->atime.seconds;
  240.     spriteAttrPtr->accessTime.microseconds    = nfsAttrPtr->atime.useconds;
  241.     spriteAttrPtr->descModifyTime.seconds    = nfsAttrPtr->ctime.seconds;
  242.     spriteAttrPtr->descModifyTime.microseconds    = nfsAttrPtr->ctime.useconds;
  243.     spriteAttrPtr->dataModifyTime.seconds    = nfsAttrPtr->mtime.seconds;
  244.     spriteAttrPtr->dataModifyTime.microseconds    = nfsAttrPtr->mtime.useconds;
  245.     /*
  246.      * Sprite "blocks" means 1K.  Unix "blocks" mean 512 bytes.
  247.      * In both cases, blocksize is the file system block size, which
  248.      * has nothing to do with the units of the blocksize field!
  249.      */
  250.     spriteAttrPtr->blocks        = nfsAttrPtr->blocks / 2;
  251.     spriteAttrPtr->blockSize        = nfsAttrPtr->blocksize;
  252.     spriteAttrPtr->version        = nfsAttrPtr->mtime.seconds;
  253.     spriteAttrPtr->userType        = 0;
  254. }
  255.  
  256. /*
  257.  *----------------------------------------------------------------------
  258.  *
  259.  * NfsSetAttrStream --
  260.  *
  261.  *    PDEV_SET_ATTR callback to set attributes of an open NFS file.
  262.  *
  263.  * Results:
  264.  *    None.
  265.  *
  266.  * Side effects
  267.  *    None.
  268.  *
  269.  *----------------------------------------------------------------------
  270.  */
  271. /*ARGSUSED*/
  272. ReturnStatus
  273. NfsSetAttrStream(streamPtr, flags, uid, gid, spriteAttrPtr, selectBitsPtr)
  274.     Pdev_Stream *streamPtr;
  275.     int flags;            /* What attributes to set */
  276.     int uid;            /* UserID of process doing the set attr */
  277.     int gid;            /* GroupID of process doing the set attr */
  278.     Fs_Attributes *spriteAttrPtr;
  279.     int *selectBitsPtr;
  280. {
  281.     register Fs_FileID *fileIDPtr = (Fs_FileID *)streamPtr->clientData;
  282.     register nfs_fh *handlePtr;
  283.     register int status;
  284.     NfsState *nfsPtr;
  285.     sattrargs sattrArgs;
  286.     attrstat attrStat;
  287.  
  288.     if (fileIDPtr->minor >= 0 && fileIDPtr->minor < nfsFileTableSize) {
  289.     handlePtr = nfsFileTable[fileIDPtr->minor]->handlePtr;
  290.     nfsPtr = (NfsState *)fileIDPtr->serverID;
  291.     nfsPtr->nfsClnt->cl_auth = nfsFileTable[fileIDPtr->minor]->authPtr;
  292.  
  293.     bcopy((char *)handlePtr, (char *)&sattrArgs.file, sizeof(nfs_fh));
  294.     SpriteToNfsAttr(flags, spriteAttrPtr, &sattrArgs.attributes);
  295.     if (clnt_call(nfsPtr->nfsClnt, NFSPROC_SETATTR, xdr_sattrargs,
  296.             &sattrArgs, xdr_attrstat, &attrStat, nfsTimeout)
  297.             != RPC_SUCCESS) {
  298.         clnt_perror(nfsPtr->nfsClnt, "NFSPROC_SETATTR");
  299.         status = FAILURE;
  300.     } else {
  301.         status = NfsStatusMap(((int)attrStat.status));
  302.     }
  303.     } else {
  304.     printf("NfsSetAttrStream: bad fileID <%d,%d,%d,%d>\n", fileIDPtr->type,
  305.         fileIDPtr->serverID, fileIDPtr->major, fileIDPtr->minor);
  306.     status = FAILURE;
  307.     }
  308.     *selectBitsPtr = FS_READABLE | FS_WRITABLE;
  309.     return(status);
  310. }
  311.  
  312. /*
  313.  *----------------------------------------------------------------------
  314.  *
  315.  * SpriteToNfsAttr --
  316.  *
  317.  *    Map from Sprite to NFS attributes.
  318.  *
  319.  * Results:
  320.  *    Fills in the NFS attributes from the Sprite ones.
  321.  *
  322.  * Side effects
  323.  *    None.
  324.  *
  325.  *----------------------------------------------------------------------
  326.  */
  327. void
  328. SpriteToNfsAttr(flags, spriteAttrPtr, nfsAttrPtr)
  329.     register int flags;            /* Indicate which attrs to set */
  330.     register Fs_Attributes *spriteAttrPtr;
  331.     register sattr *nfsAttrPtr;
  332. {
  333.     if (flags & FS_SET_MODE) {
  334.     nfsAttrPtr->mode = spriteAttrPtr->permissions & 07777;
  335.     } else {
  336.     nfsAttrPtr->mode = -1;
  337.     }
  338.     if (flags & FS_SET_OWNER) {
  339.     nfsAttrPtr->uid        = spriteAttrPtr->uid;
  340.     nfsAttrPtr->gid        = spriteAttrPtr->gid;
  341.     } else {
  342.     nfsAttrPtr->uid        = -1;
  343.     nfsAttrPtr->gid        = -1;
  344.     }
  345.     nfsAttrPtr->size        = -1;        /* Not used for truncate */
  346.     if (flags & FS_SET_TIMES) {
  347.     nfsAttrPtr->atime.seconds  = spriteAttrPtr->accessTime.seconds;
  348.     nfsAttrPtr->atime.useconds = spriteAttrPtr->accessTime.microseconds;
  349.     nfsAttrPtr->mtime.seconds  = spriteAttrPtr->dataModifyTime.seconds;
  350.     nfsAttrPtr->mtime.useconds = spriteAttrPtr->dataModifyTime.microseconds;
  351.     } else {
  352.     nfsAttrPtr->atime.seconds  = -1;
  353.     nfsAttrPtr->atime.useconds = -1;
  354.     nfsAttrPtr->mtime.seconds  = -1;
  355.     nfsAttrPtr->mtime.useconds = -1;
  356.     }
  357. }
  358.  
  359. /*
  360.  *----------------------------------------------------------------------
  361.  *
  362.  * NfsCacheAttributes --
  363.  *
  364.  *    Cache NFS attributes.
  365.  *
  366.  * Results:
  367.  *    None.
  368.  *
  369.  * Side effects
  370.  *    Tucks away the attributes with a coarse date stamp.
  371.  *
  372.  *----------------------------------------------------------------------
  373.  */
  374. void
  375. NfsCacheAttributes(fileIDPtr, nfsAttrPtr)
  376.     register Fs_FileID *fileIDPtr;
  377.     register fattr *nfsAttrPtr;
  378. {
  379.     return;
  380. }
  381.  
  382.